package com.njwb.day15.zqzb.ios.io4;

import java.io.*;

public class InputAndOutDemo {
    public static void main(String[] args) {
        //既有读取，又有写入
        InputStream inputStream = null ;
        OutputStream outputStream = null ;
        try {
            inputStream   = new FileInputStream("C:\\Users\\Administrator\\Desktop\\Snipaste_2025-07-29_14-15-18.png");
            outputStream = new FileOutputStream("F:\\vscode.png");
            //读写操作
            byte[] buffer = new byte[1024] ;
            int length = 0 ;
            //读
            long startTime = System.currentTimeMillis() ;
            while((length = inputStream.read(buffer))!=-1) {
                //写
                outputStream.write(buffer,0,length);
            }
            long endTime = System.currentTimeMillis();
            System.out.println("拷贝用了："+(endTime-startTime)+"毫秒");

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if(inputStream!=null) {
                try {
                    inputStream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

            if(outputStream!=null) {
                try {
                    outputStream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }


    }
}
